package com.wc.AlgoOJ.SQ12L3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/11 18:19
 * @description 区间覆盖
 * http://43.138.190.70:8888/p/SQ12L3
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxN = (int) 1e6;
//        int[] dp = new int[maxN + 7];
        int[][] se = new int[n][2];
        for (int i = 0; i < n; i++) {
            se[i][0] = sc.nextInt();
            se[i][1] = sc.nextInt();
        }
        Arrays.sort(se, Comparator.comparingInt(a -> a[0]));
        Arrays.sort(se, Comparator.comparingInt(a -> a[1]));
        int end = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (se[i][0] >= end) {
                end = se[i][1];
                ans++;
            }
        }
        System.out.println(ans);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
